<template>
	<section>
		<el-col :span="8" class="toolbar">
			<el-form label-width="120px" >
				<el-form-item label="奖励道具">
					<!--<el-input v-model="deploy.firstLoginRewardType" placeholder="奖励道具"></el-input>-->
					<el-radio-group v-model="type">
						<el-radio :label="1">金币</el-radio>
						<!--<el-radio :label="2">奖励点</el-radio>-->
					</el-radio-group>
				</el-form-item>
				<el-form-item label="活动1">
					<!--<el-input v-model="deploy.firstLoginRewardType" placeholder="奖励道具"></el-input>-->
					<el-radio-group v-model="activity">
						<el-radio :label="1">开启</el-radio>
						<el-radio :label="0">关闭</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="金币数量">
					<el-input v-model="gold.firstLoginRewardAmount" placeholder="金币数量" style="width: 30%"></el-input>
				</el-form-item>
				<!--<el-form-item label="奖励点数量" v-if="type == 2">-->
					<!--<el-input v-model="deploy.firstLoginRewardAmount" placeholder="奖励点数量" style="width: 30%"></el-input>-->
				<!--</el-form-item>-->
				<el-form-item>
					<el-button type="primary" size="medium" @click="handleAdd">更新</el-button>
				</el-form-item>
			</el-form>
		</el-col>
	</section>
</template>
<script>
    export default {
        data(){
            return{
                type:1,
                activity:0,
                deploy:{},
				gold:{},
				upload:{}
            }
        },
        created(){
            this.getList()
        },
        methods:{
            getList(){
                this.$axios.get('/firstlogin-reward-configs',{},this.global().token).then((res)=>{
                    if (res.status == 200){
                        if(res.data.A001 == 'YES'){
                            this.activity = 1
						}
                        // this.type = parseInt(res.data.firstLoginRewardType)
						if (res.data.firstLoginRewardType == 1){
                            this.gold = res.data
                            this.gold.firstLoginRewardAmount = parseInt(this.gold.firstLoginRewardAmount)/1000
						}else{
						    this.deploy = res.data
                            this.deploy.firstLoginRewardAmount = parseInt(this.deploy.firstLoginRewardAmount)/1000
						}
                    }else{
                        this.$message({message: res.data, type: 'error'});
                    }
                })
            },
            handleAdd(){
                if (this.type == 1){
                    if (this.gold.firstLoginRewardAmount == ''){
                        this.$message({message: '数量不能为空', type: 'error'});
                    }else{
                        this.upload.firstLoginRewardType = parseInt(this.type)
                        this.upload.firstLoginRewardAmount = parseInt(this.gold.firstLoginRewardAmount) * 1000
						this.upload.A001  = this.activity.toString().replace(0,'NO').replace(1,'YES')
						console.log(this.upload.A001)
                        this.$axios.patch('/firstlogin-reward-configs',this.upload,this.global().token).then((res)=>{
                            if (res.status == 200){
                                this.$message({message: '更新成功', type: 'success'});
                                // location.reload()
                                this.getList()
                            }else{
                                this.$message({message: res.data, type: 'error'});
                            }
                        })
                    }
				}else{
                    if (this.deploy.firstLoginRewardAmount == ''){
                        this.$message({message: '数量不能为空', type: 'error'});
                    }else{
                        this.upload.firstLoginRewardType = parseInt(this.type)
                        this.upload.firstLoginRewardAmount = parseInt(this.deploy.firstLoginRewardAmount) * 1000
                        this.$axios.patch('/firstlogin-reward-configs',this.upload,this.global().token).then((res)=>{
                            if (res.status == 200){
                                this.$message({message: '更新成功', type: 'success'});
                                // location.reload()
                                this.getList()
                            }else{
                                this.$message({message: res.data, type: 'error'});
                            }
                        })
                    }
				}

            }
        }
    }
</script>
<style scoped lang="stylus">
	.toolbar
		padding-top:30px
	.toolbar .el-form-item
		margin-bottom 30px
</style>